package com.cn.wanxi.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.util.ImgUpload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/upload-img")
public class WandEditorServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ImgUpload.upload(req);
//        最终存放图片完成后需要得到路径
        String url = (String) req.getAttribute("imgHref");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("url", url);
        resp.getWriter().println(jsonObject);
    }
}
